﻿@using System.Collections.Generic
@using System.Linq
@using Microsoft.AspNetCore.Http
@using Microsoft.AspNetCore.Http.Authentication
@model LoginViewModel
@inject SignInManager<NccUser> SignInManager

@{
    Title = "Log in";
    //Layout = Constants.SiteLayoutName;
    Layout = "_LoginLayout";
}@*<h3 class="text-center">@_T[Title]</h3>*@

<hr />
<div class="row" style="max-width:800px; margin:0 auto;">

    @{
        var loginProviders = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToList();
        if (loginProviders.Count == 0)
        {
            <div style="max-width:350px; margin:0 auto;">
                <section>
                    <a href="#loginForm"></a>
                    <form asp-route-returnurl="@ViewData["ReturnUrl"]" method="post">
                        <h4>@_T["Use a local account to log in."]</h4>
                        <hr />
                        <div asp-validation-summary="All" class="text-danger"></div>
                        <div class="form-group">
                            <label asp-for="Email"></label>
                            <input asp-for="Email" class="form-control" />
                            <span asp-validation-for="Email" class="text-danger"></span>
                        </div>
                        <div class="form-group">
                            <label asp-for="Password"></label>
                            <input asp-for="Password" class="form-control" />
                            <span asp-validation-for="Password" class="text-danger"></span>
                        </div>
                        <div class="form-group text-center">
                            <div class="checkbox">
                                <label asp-for="RememberMe">
                                    <input asp-for="RememberMe" />
                                    @Html.DisplayNameFor(m => m.RememberMe)
                                </label>
                            </div>
                        </div>
                        <div class="form-group text-center">
                            <a href="/" class="btn btn-default">@_T["Back"]</a>
                            <button type="submit" class="btn btn-primary">@_T["Log in"]</button>
                        </div>
                        <div class="form-group">
                            <div class="pull-left">
                                <a asp-action="ForgotPassword">@_T["Forgot your password?"]</a>
                            </div>
                            <div class="pull-right">
                                @if (GlobalContext.WebSite.AllowRegistration)
                                {
                                    <a asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]">@_T["Register as a new user?"]</a>
                                }
                                
                            </div>
                        </div>
                    </form>
                </section>
            </div>
        }
        else
        {
            <div style="max-width:350px; margin:0 auto;">
                <section>
                    <a href="#loginForm"></a>
                    <form asp-route-returnurl="@ViewData["ReturnUrl"]" method="post">
                        <h4>@_T["Use a local account to log in."]</h4>
                        <hr />
                        <div asp-validation-summary="All" class="text-danger"></div>
                        <div class="form-group">
                            <label asp-for="Email"></label>
                            <input asp-for="Email" class="form-control" />
                            <span asp-validation-for="Email" class="text-danger"></span>
                        </div>
                        <div class="form-group">
                            <label asp-for="Password"></label>
                            <input asp-for="Password" class="form-control" />
                            <span asp-validation-for="Password" class="text-danger"></span>
                        </div>
                        <div class="form-group text-center">
                            <div class="checkbox">
                                <label asp-for="RememberMe">
                                    <input asp-for="RememberMe" />
                                    @Html.DisplayNameFor(m => m.RememberMe)
                                </label>
                            </div>
                        </div>
                        <div class="form-group text-center">
                            <a href="/" class="btn btn-default">@_T["Back"]</a>
                            <button type="submit" class="btn btn-primary">@_T["Log in"]</button>
                        </div>
                        <div class="form-group">
                            <div class="pull-left">
                                <a asp-action="ForgotPassword">@_T["Forgot your password?"]</a>
                            </div>
                            <div class="pull-right">
                                <a asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]">@_T["Register as a new user?"]</a>
                            </div>
                        </div>
                    </form>
                </section>
            </div>

            <br />
            <hr />
            <br />

            <div style="width:350px; margin:0 auto;">
                <section>
                    <h4>Use another service to log in.</h4>
                    <hr />
                    <form asp-action="ExternalLogin" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">
                        <div>
                            <p>
                                @foreach (var provider in loginProviders)
                                {
                                    <button type="submit" class="btn btn-default" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.Name</button>
                                }
                            </p>
                        </div>
                    </form>
                </section>
            </div>
            <div style="clear:both;"></div>
        }
    }
</div>


@section Scripts {
    @await Html.PartialAsync("_ValidationScriptsPartial")
}
